<?php
namespace Home\Controller;
use Think\Controller;

class JmxxcxController extends Controller {
	public function xx_query() {
		$this->display();
	}
	public function rentihuaxiang() {
		$this->display();
	}
	public function gr_xiangxi() {
		$glModel = D("JmxxcxView");
		$id = isset($_GET['id']) ? intval($_GET['id']) : "";
		$where = array();
		$where['id'] = array('eq',"$id");
 		$zn_che = $glModel->where($where)->select();
 		$this->assign('grxx',$zn_che);
		$this->display();
	}
	public function ren_select(){
		$Model = D("JmxxcxView");
		$where = array();
		
		$name = $_POST["name"];
	    $guoji = $_POST["guoji"];
	    $date = $_POST["date"];
	    $idcard = $_POST["idcard"];
	    $minzu = $_POST["minzu"];
	    $sex = $_POST["sex"];
	    $education = $_POST["education"];
	    $hunyin = $_POST["hunyin"];
	    $zhongdian = $_POST["zhongdian"];

	    if ($name) {
	    	$where['name'] = array('like',"%$name%");
	    }
	    if ($guoji) {
	    	$where['guoji'] = array('like',"%$guoji%");
	    }
	    if ($date) {
	    	$where['date'] = array('eq',"$date");
	    }
	    if($idcard){
	    	$where['idcard'] = array('eq',"$idcard");
	    } 
	    if ($minzu) {
	    	$where['minzu'] = array('like',"%$minzu%");
	    }
	    if ($sex<>-1) {
	    	$where['sex'] = array('eq',"$sex");
	    }
	    if ($education) {
	    	$where['education'] = array('like',"%$education%");
	    }
	    if ($hunyin<>-1) {
	    	if($hunyin==1){
	    		$hunyin = "已婚";
	    	}else{
	    		$hunyin = "未婚";
	    	}
	    	$where['hunyin'] = array('eq',"$hunyin");
	    }
	    if ($zhongdian<>-1) {
	    	$where['is_zhongdian'] = array('eq',"$zhongdian");
	    }

	    $zn_rencount = $Model->where($where)->count(); 
	    $zn_ren = $Model->where($where)->select();

	    if ($zn_rencount > 0){   
	    	echo json_encode($zn_ren);       
	    }
	    else{
	    	echo json_encode(0);
	    }
	}
	public function ren_xxylk(){
		$glModel = D("JmxxcxView");
		
		$id = $_POST["id"];

		$where = array();
 		$where['id'] = array('eq',"$id");
 		$zn_che = $glModel->where($where)->find();
    
	    echo json_encode($zn_che);        
	}
	public function danwei_select(){
		$Model = D("dwcx");

		$where = array();
		
		$workname = $_POST["workname"];
	    $location = $_POST["location"];
	    $faren_name = $_POST["faren_name"];
	    $baowei_name = $_POST["baowei_name"];

	    if ($workname) {
	    	$where['workname'] = array('like',"%$workname%");
	    }
	    if ($faren_name) {
	    	$where['faren_name'] = array('like',"%$faren_name%");
	    }
	    if($baowei_name){
	    	$where['baowei_name'] = array('like',"%$baowei_name%");
	    } 
	    if ($location) {
	    	$where['location'] = array('like',"%$location%");
	    }
	    // $zn_danweicount = $Model->where($where)->getLastSql();;

	    $zn_danweicount = $Model->where($where)->count();  
	    $zn_danwei = $Model->where($where)->select();

	    if ($zn_danweicount > 0){   
	    	echo json_encode($zn_danwei);       
	    }
	    else{
	    	echo json_encode(0);
	    }
	}
	public function danwei_xxylk(){
		$glModel = D("dwcx");
		
		$id = $_POST["id"];

		$where = array();
 		$where['danwei_id'] = array('eq',"$id");
 		$zn_danwei = $glModel->where($where)->find();
    
	    echo json_encode($zn_danwei);        
	}
	public function che_select(){
		// $zn_cheModel = D("zn_che");
		// $zn_peopleModel = D("zn_people");
		$Model = D("JmxxcxView");


		// 相同写法
		// $Model = D("JmxxcxView");
		// $Model->table('think_JmxxcxView JmxxcxView,think_category Category,think_user User')
		//  ->field('JmxxcxView.id,JmxxcxView.name,JmxxcxView.title,Category.title as category_name,User.name as username')
		//  ->order('JmxxcxView.id desc')
		//  ->where('JmxxcxView.category_id=Category.id AND JmxxcxView.user_id=User.id')
		//  ->select();

		// var_dump($Model);exit();
		$where = array();
		
		$che_number = $_POST["che_number"];
	    $name = $_POST["name"];
	    $color = $_POST["color"];
	    $type = $_POST["type"];

	    if ($che_number) {
	    	$where['che_number'] = array('like',"%$che_number%");
	    }
	    if ($color) {
	    	$where['color'] = array('like',"%$color%");
	    }
	    if($type){
	    	$where['type'] = array('like',"%$type%");
	    } 
	    if ($name) {
	    	// $sql = "select * from zn_people_che inner join zn_people on zn_people_che.renid = zn_people.id inner join "; 
	    	// $sql['name'] = array('like',"%$name%");
	    	$where['name'] = array('like',"%$name%");
	    }

	    $zn_checount = $Model->where($where)->count(); 
	    $zn_che = $Model->where($where)->select();

	    // $zn_checount = $zn_cheModel->where($where)->count();  
	    // $zn_che = $zn_cheModel->where($where)->select();


	    // var_dump($zn_cheModel->getLastSql());exit;
	    // print_r($zn_che);
	    // die();


		// $zn_peoplecount = $zn_peopleModel->where($where)->count();
	    // $zn_people = $zn_peopleModel->join(array('__ZN_PEOPLE_CHE__ ON __ZN_PEOPLE_CHE__.renid = __ZN_PEOPLE__.id','__ZN_CHE__ on __ZN_CHE__.cheid = __ZN_PEOPLE_CHE__.cheid'))->where($sql)->select();

	 	// $zn_people = $zn_peopleModel->where($where)->select();
	 	// $zn_people = $zn_peopleModel->join('__ZN_PEOPLE_CHE__ ON __ZN_PEOPLE_CHE__.renid = __ZN_PEOPLE__.id')->join('__ZN_CHE__ on __ZN_CHE__.cheid = __ZN_PEOPLE_CHE__.cheid')->where($where)->select();

	    if ($zn_checount > 0){   
	    	echo json_encode($zn_che);

	        // $this->assign('zn_che',$zn_che);
	        // $this->display();         
	    }
	    // if ($zn_peoplecount > 0){          
	    //     $this->assign('zn_che',$zn_people);
	    //     $this->display();        
	    // }
	    else{
	    	echo json_encode(0);
	        // $this->error("检索失败或无选定字段名的数据！",U("admin/Jmxxcx/xx_query"));
	    }
	}
	public function che_xxylk(){
		$glModel = D("JmxxcxView");
		
		$cheid = $_POST["cheid"];

		$where = array();
 		$where['cheid'] = array('eq',"$cheid");
 		$zn_che = $glModel->where($where)->find();

	    // $zn_che = $glModel->find($cheid);    此方法会出错	    
	    echo json_encode($zn_che);        
	}
	
}